package liuch.rmi;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

/**
 * 客户端 获得远程对象，并实现像调用本地方法一样调用远程服务
 */
public class Client {
    public static void main(String[] args) throws MalformedURLException {
        String url = "rmi://localhost:1234/rmiServer";
        try {
            // 获取远端服务,找到服务器端相应的服务对象存根
            IServer server = (IServer) Naming.lookup(url);
            /**
             * 打印远端服务信息
             */
            Class c = server.getClass();
            System.out.println(c.getName());
            // 获取本地存根已实现的接口类型
            Class[] interfces = c.getInterfaces();
            for (Class inter : interfces) {
                System.out.println("实现了接口" + inter.getName());
            }
            System.out.println(server.server("入参"));
        } catch (RemoteException | NotBoundException e) {
            e.printStackTrace();
        }
    }
}
